//
//  ConversationListViewController.m
//  FoodCorner
//
//  Created by apple on 16/3/14.
//  Copyright © 2016年 zhangchao. All rights reserved.
//

#import "ConversationListViewController.h"
#import <RongIMKit/RongIMKit.h>
#import "UserDataHelper.h"
#import "ConversationViewController.h"
#import <RongIMKit/RCConversationViewController.h>

@interface ConversationListViewController ()

@end

@implementation ConversationListViewController

//- (void)viewWillAppear:(BOOL)animated
//{
//    [[RCIM sharedRCIM] initWithAppKey:@"m7ua80gbu90qm"];
//    NSString *token = [UserDataHelper shareInstance].token;
//    [[RCIM sharedRCIM] connectWithToken:token success:^(NSString *userId) {
//        NSLog(@"登录成功");
//    } error:^(RCConnectErrorCode status) {
//        NSLog(@"登录失败，失败代码为：%ld",status);
//    } tokenIncorrect:^{
//        NSLog(@"登录失败，token出错");
//    }];
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置需要显示哪些类型的会话
    [self setDisplayConversationTypes:@[@(ConversationType_PRIVATE),
                                        @(ConversationType_DISCUSSION),
                                        @(ConversationType_CHATROOM),
                                        @(ConversationType_GROUP),
                                        @(ConversationType_APPSERVICE),
                                        @(ConversationType_SYSTEM)]];
    //设置需要将哪些类型的会话在会话列表中聚合显示
    [self setCollectionConversationType:@[@(ConversationType_DISCUSSION),
                                          @(ConversationType_GROUP)]];
    self.navigationItem.title = @"微聊";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"单聊" style:(UIBarButtonItemStylePlain) target:self action:@selector(clickRightButton:)];
    self.tabBarController.tabBar.hidden = YES;
}

- (void)clickRightButton:(UIBarButtonItem *)sender
{
    ConversationViewController *conversationVC = [[ConversationViewController alloc] init];
    [self.navigationController pushViewController:conversationVC animated:YES];
}

- (void)onSelectedTableRow:(RCConversationModelType)conversationModelType conversationModel:(RCConversationModel *)model atIndexPath:(NSIndexPath *)indexPath
{
    RCConversationViewController *conversationVC = [[RCConversationViewController alloc]init];
    conversationVC.conversationType = model.conversationType;
    conversationVC.targetId = @"1";
    conversationVC.title = @"单聊";
    [self.navigationController pushViewController:conversationVC animated:YES];
}

- (void)getUserInfoWithUserId:(NSString *)userId completion:(void (^)(RCUserInfo *))completion
{
    //此处为了演示写了一个用户信息
    if ([@"1" isEqual:userId]) {
        RCUserInfo *user = [[RCUserInfo alloc]init];
        user.userId = @"1";
        user.name = @"测试1";
        user.portraitUri = @"https://ss0.baidu.com/73t1bjeh1BF3odCf/it/u=1756054607,4047938258&fm=96&s=94D712D20AA1875519EB37BE0300C008";
        
        return completion(user);
    }else if([@"2" isEqual:userId]) {
        RCUserInfo *user = [[RCUserInfo alloc]init];
        user.userId = @"2";
        user.name = @"测试2";
        user.portraitUri = @"https://ss0.baidu.com/73t1bjeh1BF3odCf/it/u=1756054607,4047938258&fm=96&s=94D712D20AA1875519EB37BE0300C008";
        return completion(user);
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
